/*
 * @Descripttion: 
 * @version: 
 * @Author: cyj
 * @Date: 2022-12-09 10:48:30
 */
//发现音乐仓库
import { defineStore } from 'pinia'
import { getBanner, getSongPersonalized, getPrivateContent, getNewSongs, getNewMV } from '../api/findmusic/discover/discover'
import { getAllTag, getHighqualityTags, getTopHighquality, getHotTag } from '../api/findmusic/singslist/singslist'
export const useDiscover = defineStore('discover', {
    state: () => {
        return {
            //个性推荐
            //轮播图数组
            bannerList: [],
            //推荐歌单数组
            personalized: [],
            //独家放送数组
            privateContent: [],
            //最新音乐数组
            newSongList: [],
            //最新mv数组
            newMvList: [],
            //个性推荐

            //歌单
            //精品歌单标签列表
            highQualityTagsList: [],
            //热门歌单分类标签
            hotTagsList: [],

            //顶部精品歌单
            topSongsList: [],
            //歌单分类
            //all
            all: {},
            categories: {},

            //语种数组
            langList: [],
            //风格数组
            styleList: [],
            //场景数组
            senseList: [],
            //情感数组
            moodList: [],
            //主题数组
            themeList: [],
            //歌单

            //最新音乐
            weekNewSongsList: []

        }
    },
    getters: {

    },
    actions: {
        //个性推荐所有数据
        //获取轮播图数据并存到仓库中
        async getBanners() {
            let res = await getBanner()
            if (res.status === 200) {
                this.bannerList = res.data.banners
            }
        },
        //获取推荐歌单数组 并存到仓库中
        async getPersonalized() {
            let res = await getSongPersonalized(12)
            if (res.status === 200) {
                this.personalized = res.data.result
            }
        },

        //获取取独家放送数组并存到仓库中
        async getPrivateContent() {
            let res = await getPrivateContent()
            if (res.status === 200) {
                this.privateContent = res.data.result
            }
        },

        //获取最新音乐数组并存到仓库中
        async getNewSongList(limit) {
            let res = await getNewSongs(limit)
            if (res.status === 200) {
                this.newSongList = res.data.result
            }
        },

        async getNewMV() {
            let res = await getNewMV()
            if (res.status === 200) {
                this.newMvList = res.data.result
            }
        },
        //个性推荐所有数据

        //歌单所有数据
        //获取精品歌单标签数据
        async getHighqualityTags() {
            let res = await getHighqualityTags()
            if (res.status === 200) {
                this.highQualityTagsList = res.data.tags
            }
        },

        //获取热门歌单分类标签
        async getHotTag() {
            let res = await getHotTag()
            if (res.status === 200)
                this.hotTagsList = res.data.tags
        },

        //获取歌单所有分类标签
        async getAllTags() {
            let res = await getAllTag()
            if (res.status === 200) {
                const { all, categories, sub } = res.data
                this.all = all
                this.categories = categories
                for (const item of sub) {
                    if (item.category === 0)
                        this.langList.push(item)
                    else if (item.category === 1)
                        this.styleList.push(item)
                    else if (item.category === 2)
                        this.senseList.push(item)
                    else if (item.category === 3)
                        this.moodList.push(item)
                    else
                        this.themeList.push(item)
                }
            }
        },

        //获取歌单
        // async getSongs(cat, offset) {
        //     let res = await getSongList(cat, offset)
        //     if (res.status === 200) {
        //         this.songsList = res.data.playlists
        //     }
        // },

        //获取顶部歌单 —— 取1个
        async getTopSongList(cat) {
            let res = await getTopHighquality(cat)
            if (res.status === 200) {
                this.topSongsList = res.data.playlists
            }
        },



    },

    persist: {
        
    }
})